package com.ljfiction.book.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.ljfiction.book.Baner.Book;
import com.ljfiction.book.Baner.MyBookBean;
import com.ljfiction.book.MyView.SuperButton;
import com.ljfiction.book.R;

import com.ljfiction.book.tools.ScreenUtils;
import com.ljfiction.book.tools.TimeTool;
import com.zhy.autolayout.utils.AutoUtils;


import java.util.ArrayList;
import java.util.List;


/**
 * Created by Administrator on 2017/7/25.
 */

public class MyBookAdapter extends BaseQuickAdapter<MyBookBean.DataBean, BaseViewHolder> {
    private List<Book> bookList = new ArrayList<>();
    private Context context;

    public MyBookAdapter(@LayoutRes int layoutResId, @Nullable List<MyBookBean.DataBean> data) {
        super(layoutResId, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, MyBookBean.DataBean item) {
        AutoUtils.autoSize(helper.itemView);
        if (helper.getLayoutPosition() == 0) {
            ((ImageView)helper.getView(R.id.mybookimage)).setImageResource(R.drawable.addbook);
            helper.getView(R.id.mybookname).setVisibility(View.INVISIBLE);
            helper.getView(R.id.mybookgettime).setVisibility(View.INVISIBLE);
            helper.getView(R.id.isqianyue).setVisibility(View.INVISIBLE);
        }else {
            helper.getView(R.id.mybookname).setVisibility(View.VISIBLE);
            helper.getView(R.id.mybookgettime).setVisibility(View.VISIBLE);
            helper.getView(R.id.isqianyue).setVisibility(View.VISIBLE);
            Glide.with(mContext).load(item.getBookImage()).override(ScreenUtils.getNum(mContext,108),ScreenUtils.getNum(mContext,144)).into((ImageView)helper.getView(R.id.mybookimage));
            helper.setText(R.id.mybookname,item.getBookName());
            if (item.getBookStatus()==0){
                helper.setTextColor(R.id.mybookgettime, Color.parseColor("#999999"));
                helper.setText(R.id.mybookgettime,TimeTool.getDateTime(item.getLastUpdateTime())+"更新");
            }else {
                helper.setTextColor(R.id.mybookgettime, Color.parseColor("#FF6F00"));
                helper.setText(R.id.mybookgettime,"完结");
            }
            if (item.getBookCheckStatus()==0) {
                ((SuperButton)helper.getView(R.id.isqianyue)).setsSolidColor("#999999");
                helper.getView(R.id.isqianyue).setVisibility(View.VISIBLE);
                helper.setText(R.id.isqianyue,"未审核");
            } else if (item.getBookCheckStatus()==1&&item.getBookAuthorization()==0){
                ((SuperButton)helper.getView(R.id.isqianyue)).setsSolidColor("#999999");
                helper.getView(R.id.isqianyue).setVisibility(View.VISIBLE);
                helper.setText(R.id.isqianyue,"未签约");
            }else if (item.getBookCheckStatus()==1&&item.getBookAuthorization()==1){
                ((SuperButton)helper.getView(R.id.isqianyue)).setsSolidColor("#75D5F8");
                helper.getView(R.id.isqianyue).setVisibility(View.VISIBLE);
                helper.setText(R.id.isqianyue,"签约");
            }else if (item.getBookCheckStatus()==1){
                helper.getView(R.id.isqianyue).setVisibility(View.GONE);
            } else if (item.getBookCheckStatus()==2){
                ((SuperButton)helper.getView(R.id.isqianyue)).setsSolidColor("#f77583");
                helper.getView(R.id.isqianyue).setVisibility(View.VISIBLE);
                helper.setText(R.id.isqianyue,"VIP");
            }
        }
    }
}
